
//
// 120128 - AH - (Garage) Created.
// 120131 - AH - (Huset *) Factors rendered on yellow background.
// 120321 - AH - Removed @Override for interface method (1.5 compatible).
//

package org.soekrat.gui.swing.ptable;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

import org.soekrat.engine.ontology.ptable.Product;
import org.soekrat.engine.ontology.ptable.ProductTable;
import org.soekrat.engine.ontology.ptable.ProductTableFactor;

/**
 * <p>
 *   {@link TableCellRenderer} used for 
 *   {@link JTable} view showing 
 *   {@link ProductTable}.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
public final class ProductTableCellRenderer implements TableCellRenderer 
{
  private final DefaultTableCellRenderer m_dtcr=new DefaultTableCellRenderer();
  
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public ProductTableCellRenderer(){}

  // Specified in TableCellRenderer.
  public Component getTableCellRendererComponent(JTable table, Object val,
    boolean isSelected, boolean hasFocus, int row, int col)
  {
    m_dtcr.setBackground(Color.WHITE);
    
    String txt=(val==null) ? "" : val.toString();
    if (val instanceof Product)
    {
      txt=((Product)val).getSoekratName().getPure();
    }
    else if (val instanceof ProductTableFactor)
    {
      txt=((ProductTableFactor)val).getSoekratName().getPure();
      m_dtcr.setBackground(Color.YELLOW);
    }
    
    return m_dtcr.getTableCellRendererComponent(table, txt, isSelected, 
      hasFocus, row, col);
  }
   
}
